<?php 
// +----------------------------------------------------------------------
// | 产品相关类
// +----------------------------------------------------------------------
// | Author: TongBC <501468940@qq.com>
// +----------------------------------------------------------------------
// | Date  : 2015/05/26
// +----------------------------------------------------------------------
// | 特别说明：个人文件，请勿修改，如需修改，请采用类的继承或联系本人
// +----------------------------------------------------------------------
namespace abc777;

class Product{
	
	// 获取自己在线销售的产品
	public static function ownSale(){
		$sid = $_SESSION['sid'];$clsResult = array();
		$sql = "select id as pid,p_name from uu_products where apply_did=$sid and apply_limit=1 and p_status=0";
		$GLOBALS['le']->query($sql);
		while($row=$GLOBALS['le']->fetch_assoc()){
			$clsResult[] = $row;
		}
		return $clsResult;
	}
	
	// 获取指定产品价格 
	// $mode   获取类型 0 分销价 1 零售价 2 都获取
	// $lower  指定日期获取不到价格是否获取最低价
	public static function Price($s, $pid, $aid, $today, $mode=2, $lower=true){
		
		$clsResult = array('js'=>-1, 'ls'=>-1);// 返回的价格数组
		$account = $_SESSION['saccount'];
		if($mode==0 || $mode==2){// 获取结算价
			$simxml = $s->Dynamic_Price_And_Storage($account, $pid, $today, 1, 0, 0, $aid);
			if($simxml==105  && $lower) $simxml = $s->Dynamic_Price_And_Storage($account, $pid, $today, 2, 0, 0, $aid);
			if($simxml==105 || $simxml==1065) return $clsResult;
			$simxml_o = simplexml_load_string($simxml);
			$clsResult['js'] = (string)$simxml_o->Rec->UUsprice/100;
		}
		
		if($mode==1 || $mode==2 ){// 获取零售价
			$simxml = $s->Dynamic_Price_And_Storage($account, $pid, $today, 1, 1, 0, $aid);
			if($simxml==105 && $lower) $simxml = $s->Dynamic_Price_And_Storage($account, $pid, $today, 2, 1, 0, $aid);
			if($simxml==105 || $simxml==1065) return $clsResult;
			$simxml_o = simplexml_load_string($simxml);
			$clsResult['ls'] = (string)$simxml_o->Rec->UUsprice/100;
		}
		return $clsResult;
	}
	
	// 获取指定产品价格 
	// $mode   获取类型 0 分销价 1 零售价 2 都获取
	// $lower  指定日期获取不到价格是否获取最低价
	public static function Dynamic_Price_And_Storage($inside, $account, $pid, $aid, $today, $mode=2, $lower=true){
		
		$clsResult = array('js'=>array('p'=>-1,'s'=>-1), 'ls'=>array('p'=>-1,'s'=>-1));// 返回的价格数组
		if($mode==0 || $mode==2){// 获取结算价
			$simxml = $inside->Dynamic_Price_And_Storage($account, $pid, $today, 1, 0, 1, $aid);
			if($simxml==105  && $lower) $simxml = $inside->Dynamic_Price_And_Storage($account, $pid, $today, 2, 0, 1, $aid);
			if($simxml==105 || $simxml==1065) return $clsResult;
			$simxml_o = simplexml_load_string($simxml);
			$clsResult['js']['p'] = (string)$simxml_o->Rec->UUsprice/100;
			$clsResult['js']['s'] = (string)$simxml_o->Rec->UUstorage;
		}
		
		if($mode==1 || $mode==2 ){// 获取零售价
			$simxml = $inside->Dynamic_Price_And_Storage($account, $pid, $today, 1, 1, 1, $aid);
			if($simxml==105 && $lower) $simxml = $inside->Dynamic_Price_And_Storage($account, $pid, $today, 2, 1, 1, $aid);
			if($simxml==105 || $simxml==1065) return $clsResult;
			$simxml_o = simplexml_load_string($simxml);
			$clsResult['ls']['p'] = (string)$simxml_o->Rec->UUsprice/100;
			$clsResult['ls']['s'] = (string)$simxml_o->Rec->UUstorage;
		}
		return $clsResult;
	}
}
